View Javadoc

1   // ProgramHeader.java, created Wed Mar  6 18:38:47 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Linker.ELF;
5   
6   import java.io.IOException;
7   
8   /***
9    *
10   * @author  John Whaley <jwhaley@alum.mit.edu>
11   * @version $Id: ProgramHeader.java 1451 2004-03-09 06:27:08Z jwhaley $
12   */
13  public abstract class ProgramHeader implements ELFConstants {
14  
15      protected int offset;
16      protected int vaddr;
17      protected int paddr;
18      protected int filesz;
19      protected int memsz;
20      protected int flags;
21      protected int align;
22      
23      public abstract int getType();
24      public int getOffset() { return offset; }
25      public int getVAddr() { return vaddr; }
26      public int getPAddr() { return paddr; }
27      public int getFileSz() { return filesz; }
28      public int getMemSz() { return memsz; }
29      public int getFlags() { return flags; }
30      public int getAlign() { return align; }
31  
32      public void writeHeader(ELFImpl file) throws IOException {
33          file.write_word(this.getType());
34          file.write_off(this.getOffset());
35          file.write_addr(this.getVAddr());
36          file.write_addr(this.getPAddr());
37          file.write_word(this.getFileSz());
38          file.write_word(this.getMemSz());
39          file.write_word(this.getFlags());
40          file.write_word(this.getAlign());
41      }
42  
43      public static class NullProgramHeader extends ProgramHeader {
44          protected String name;
45          protected byte[] desc;
46          protected int type;
47          public final int getType() { return PT_NULL; }
48      }
49      public static class LoadProgramHeader extends ProgramHeader {
50          public final int getType() { return PT_LOAD; }
51      }
52      public static class DynamicProgramHeader extends ProgramHeader {
53          public final int getType() { return PT_DYNAMIC; }
54      }
55      public static class InterpProgramHeader extends ProgramHeader {
56          public final int getType() { return PT_INTERP; }
57      }
58      public static class NoteProgramHeader extends ProgramHeader {
59          public final int getType() { return PT_NOTE; }
60      }
61      public static class PHdrProgramHeader extends ProgramHeader {
62          public final int getType() { return PT_PHDR; }
63      }
64  
65      public static int getSize() { return 32; }
66  }